from sklearn import datasets
import matplotlib.pyplot as plt
import seaborn as sns
import tensorflow as tf


def build_net():
    inputs = tf.placeholder(tf.float32, [None, 4])
    labels = tf.placeholder(tf.float32, [None, 1])
    weights = tf.Variable(tf.random_uniform([4, 1]))
    bias = tf.Variable(tf.zeros([1, 1]))
    outs = tf.sigmoid(tf.matmul(inputs, weights) + bias)
    loss = tf.reduce_mean(tf.square(outs - labels))
    optimizer = tf.train.GradientDescentOptimizer(0.1).minimize(loss)
    return inputs, labels, optimizer, outs
    pass


def main():
    iris = datasets.load_iris()
    x = iris['data'][:100]
    y = iris['target'][:100].reshape(-1, 1)
    print(x.shape, y.shape)
    print(x, y)
    inputs, labels, optimizer, outs = build_net()
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        for epoch in range(200):
            _, out = sess.run([optimizer, outs], feed_dict={inputs: x, labels: y})
            print('Epoch :', epoch, out, y)
    # print(iris)
    pass


if __name__ == '__main__':
    main()
